<?php

function getNewDatabaseConnection() {
    print ("server: " . $_SERVER["SERVER_NAME"]);
    if ($_SERVER["SERVER_NAME"] == "foggybridge-dev.herokuapp.com") {
        echo '<br/> you used the foggy bridge connection!';
        $con = pg_connect("dbname=d3ssa1qqefe350 host=ec2-54-225-102-116.compute-1.amazonaws.com port=5432 user=tdxvcnxmulaxha password=bm4EXrLwbAb6AKxnmsFiwieeZS sslmode=require") or die("Error in connection: " . pg_last_error());
    } else {
        echo '<br/> you used the local connection...';
        $con = pg_connect("host=localhost port=5432 dbname=foggy user=postgres password=pickles") or die("Error in connection: " . pg_last_error());    
    }
    echo "<br/>Connection success";
    return $con;
}

function closeDatabaseConnection($con) {
    // close connection
    pg_close($con);
}

function endQuery ($con, $result) {
    // free memory
    pg_free_result($result);
    // close connection
    closeDatabaseConnection($con);
}

?>